package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class JDBCDemo8_8 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection();){
            connection.setAutoCommit(false);//设置手动提交
            String sql ="update user set username=? , password =? ,nickname=? ,age=? where id=? ";
            PreparedStatement ps = connection.prepareStatement(sql);

            ps.setString(1,"lisi");
            ps.setString(2,"123456");
            ps.setString(3,"张三");
            ps.setInt(4,18);
            ps.setInt(5,2);
            int num = ps.executeUpdate();
            if(num>0){
                connection.commit();
                System.out.println("修改成功");
            }else {
                connection.rollback();
                System.out.println("修改失败");
            }

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
